<? if ($c = stack('name')) {

	$_id_component	= $DATA['components'][$c]['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	
	$_required = array('form_name', 'form_friend_name', 'form_friend_mail');

	$s = component_settings($c);

//	$DATA['components'][$c]['data']['html']
	


	if ((int) $_POST['check'] == $s['check']) {
	
		$req = array();
		foreach($_required as $v) if (!postdata($v)) $req[] = $s[$v];
		
		if (sizeof($req)) {
			diags('<p class="error">Error: Please fill the requested fields: <strong>'.implode(', ', $req).'.</strong></p>');
			unstack();
			return 1;
		}
	
		$form_name = trim(strip_tags(postdata('form_name')));
		$form_friend_name = trim(strip_tags(postdata('form_friend_name')));
		$form_friend_mail = trim(strip_tags(postdata('form_friend_mail')));
		$form_note = trim(nl2br(strip_tags(postdata('form_note'))));

// mail to friend

		$subject = str_replace('{name}', $form_name, $s['inv_subject']);
		$subject = '=?utf-8?B?'.base64_encode( stripslashes($subject)).'?=';
		
		$headers = "From: \"=?utf-8?B?".base64_encode($form_name)."?=\" <$s[adm_address]>";
		$headers .= "\r\nReply-To: \"=?utf-8?B?".base64_encode($s[adm_name])."?=\" <$s[adm_address]>";
		$headers .= "\r\nX-Mailer: PHP/".phpversion();
		$headers .= "\r\nMIME-Version: 1.0";
		$headers .= "\r\nContent-Type: text/html; charset=\"utf-8\"";
		$headers .= "\r\nContent-Transfer-Encoding: base64";

		$to = "\"=?utf-8?B?".base64_encode($form_friend_name)."?=\" <$form_friend_mail>";

		$body = str_replace(array('{name}', '{friend name}', '{note}'), array($form_name, $form_friend_name, $form_note), $s['inv_body']);
		$body = chunk_split(base64_encode(stripslashes($body)));
		
		if (@mail($to, $subject, $body, $headers))
			diags('<p class="success">Your invite has been sent.</p>');
		else {
			diags('<p class="error">Error: Invite sending failed. Please try again in a few minutes.</p>');
			unstack();
			return(1);
		}

// mail to admin

		$subject = 'Invitation has been sent from the site';
		$subject = '=?utf-8?B?'.base64_encode( stripslashes($subject)).'?=';

		$headers = "From: \"=?utf-8?B?".base64_encode($s[adm_name])."?=\" <$s[adm_address]>";
		$headers .= "\r\nX-Mailer: PHP/".phpversion();
		$headers .= "\r\nMIME-Version: 1.0";
		$headers .= "\r\nContent-Type: text/html; charset=\"utf-8\"";
		$headers .= "\r\nContent-Transfer-Encoding: base64";

		$to = $s['adm_address'];

		ob_start();
?>
<p><strong>Sender's Name:</strong> <?=$form_name?></p>
<p><strong>Friend's Name:</strong> <?=$form_friend_name?></p>
<p><strong>Friend's e-mail:</strong> <?=$form_friend_mail?></p>
<p><strong>Note:</strong><br /><?=$form_note?></p>
<?

		$body = ob_get_clean();
		$body = chunk_split(base64_encode(stripslashes($body)));
		
		@mail($to, $subject, $body, $headers);
	}


	unstack();
}

?>